/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package org.ossr.portlets.pm.service.http;

import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.util.StringPool;

import org.ossr.portlets.pm.model.PrivateMessage;

import java.util.Date;
import java.util.List;

/**
 * @author    Edgar Zavala
 * @generated
 */
public class PrivateMessageJSONSerializer {
	public static JSONObject toJSONObject(PrivateMessage model) {
		JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

		jsonObj.put("messageId", model.getMessageId());
		jsonObj.put("ownerId", model.getOwnerId());
		jsonObj.put("recepients", model.getRecepients());

		Date creationDate = model.getCreationDate();

		String creationDateJSON = StringPool.BLANK;

		if (creationDate != null) {
			creationDateJSON = String.valueOf(creationDate.getTime());
		}

		jsonObj.put("creationDate", creationDateJSON);
		jsonObj.put("isReply", model.getIsReply());

		Date replyDate = model.getReplyDate();

		String replyDateJSON = StringPool.BLANK;

		if (replyDate != null) {
			replyDateJSON = String.valueOf(replyDate.getTime());
		}

		jsonObj.put("replyDate", replyDateJSON);
		jsonObj.put("deleted", model.getDeleted());
		jsonObj.put("readed", model.getReaded());
		jsonObj.put("subject", model.getSubject());
		jsonObj.put("body", model.getBody());

		return jsonObj;
	}

	public static JSONArray toJSONArray(
		org.ossr.portlets.pm.model.PrivateMessage[] models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (PrivateMessage model : models) {
			jsonArray.put(toJSONObject(model));
		}

		return jsonArray;
	}

	public static JSONArray toJSONArray(
		org.ossr.portlets.pm.model.PrivateMessage[][] models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (PrivateMessage[] model : models) {
			jsonArray.put(toJSONArray(model));
		}

		return jsonArray;
	}

	public static JSONArray toJSONArray(
		List<org.ossr.portlets.pm.model.PrivateMessage> models) {
		JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

		for (PrivateMessage model : models) {
			jsonArray.put(toJSONObject(model));
		}

		return jsonArray;
	}
}